package com.ruoyi.project.loans.payment.controller;

import java.util.List;

import com.ruoyi.project.loans.payment.domain.PaymentDetail;
import com.ruoyi.project.loans.payment.service.IPaymentDetailService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 还款计划信息操作处理
 * 
 * @author ruoyi
 * @date 2020-06-18
 */
@Controller
@RequestMapping("/loans/paymentDetail")
public class PaymentDetailController extends BaseController
{
    private String prefix = "loans/payment";
	
	@Autowired
	private IPaymentDetailService paymentDetailService;
	
	@RequiresPermissions("payment:paymentDetail:view")
	@GetMapping("/{loanId}")
	public String paymentDetail(@PathVariable("loanId") Integer loanId,ModelMap mmap)
	{
		mmap.put("loanId",loanId);
	    return prefix + "/paymentDetail";
	}
	
	/**
	 * 查询还款计划列表
	 */
	@RequiresPermissions("payment:paymentDetail:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(PaymentDetail paymentDetail)
	{
		startPage();
        List<PaymentDetail> list = paymentDetailService.selectPaymentDetailList(paymentDetail);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出还款计划列表
	 */
	@RequiresPermissions("payment:paymentDetail:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(PaymentDetail paymentDetail)
    {
    	List<PaymentDetail> list = paymentDetailService.selectPaymentDetailList(paymentDetail);
        ExcelUtil<PaymentDetail> util = new ExcelUtil<PaymentDetail>(PaymentDetail.class);
        return util.exportExcel(list, "paymentDetail");
    }
	
	/**
	 * 新增还款计划
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存还款计划
	 */
	@RequiresPermissions("payment:paymentDetail:add")
	@Log(title = "还款计划", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(PaymentDetail paymentDetail)
	{		
		return toAjax(paymentDetailService.insertPaymentDetail(paymentDetail));
	}

	/**
	 * 修改还款计划
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Integer id, ModelMap mmap)
	{
		PaymentDetail paymentDetail = paymentDetailService.selectPaymentDetailById(id);
		mmap.put("paymentDetail", paymentDetail);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存还款计划
	 */
	@RequiresPermissions("payment:paymentDetail:edit")
	@Log(title = "还款计划", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(PaymentDetail paymentDetail)
	{		
		return toAjax(paymentDetailService.updatePaymentDetail(paymentDetail));
	}
	
	/**
	 * 删除还款计划
	 */
	@RequiresPermissions("payment:paymentDetail:remove")
	@Log(title = "还款计划", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(paymentDetailService.deletePaymentDetailByIds(ids));
	}
	
}
